package bookstudytest.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @Auther: Lee
 * @Date: 2018/6/19 09:32
 * @Description:
 */
public class SocketClient {
    public static void main(String[] args) throws IOException {
        // 要连接的服务端IP地址和端口
        String host = "127.0.0.1";
        int port = 55533;
        byte[] response = new byte[1024];
        StringBuilder sb = new StringBuilder();
        // 与服务端建立连接
        Socket socket = new Socket(host, port);
        // 建立连接后获得输出流
        OutputStream outputStream = socket.getOutputStream();
        String message = "你好";
        outputStream.write(message.getBytes("GBK"));
//        InputStream inputStream = socket.getInputStream();
//        int read ;
//        while (read=inputStream.read(response)!=-1){
//            sb.append(new String(response,0,read,"GBK"));
//        }
        System.out.println(sb.toString());
//        inputStream.close();
        outputStream.close();
        socket.close();
    }

}
